package bjtuoj;

import java.util.Arrays;
import java.util.Scanner;

/**
 * ClassName: Homework_4_A
 * Description:
 * date: 2021-11-30 21:00
 *
 * @author liyifan
 */
public class Homework_4_A {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        while (T-- > 0) {
            int N = scanner.nextInt();
            int first = 0;
            int sec = 0;
            int ans = 1000_0000_0;
            int[] arr = new int[N];
            boolean[] v = new boolean[N];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = scanner.nextInt();
            }
            if (N == 2){
                System.out.printf("%d\n", Math.abs(arr[1] - arr[0]));
                continue;
            }
            Arrays.sort(arr);
            if (N % 2 == 1) {
                int i = 0;
                while (arr[i] == 0)
                    i++;
                Arrays.fill(v, false);
                v[i] = true;
                first = first * 10 + arr[i];
                i = 0;
                int k = 0;
                while (k < N / 2) {
                    if (!v[i]) {
                        v[i] = true;
                        first = first * 10 + arr[i];
                        k++;
                    }
                    i++;
                }
                i = N - 1;
                k = 0;//计数
                while (k < N/2)
                {
                    if (!v[i])
                    {
                        v[i] = true;
                        sec = sec * 10 + arr[i];
                        k++;
                    }
                    i--;
                }
                System.out.printf("%d\n", Math.abs(first-sec));
            } else {
                for (int i = 0;i < N - 1;i++) if (arr[i] != 0 && arr[i + 1] != 0)
                {
                    first = sec = 0;
                    Arrays.fill(v, false);
                    first = first * 10 + arr[i]; v[i] = true;
                    sec = sec * 10 + arr[i+1]; v[i + 1] = true;
                    int j = 0;
                    int k = 0;
                    while (k < N / 2 - 1)
                    {
                        if (!v[j])
                        {
                            v[j] = true;
                            sec = sec * 10 + arr[j];
                            k++;
                        }
                        j++;
                    }
                    j = N - 1;
                    k = 0;
                    while (k < N / 2 - 1)
                    {
                        if (!v[j])
                        {
                            v[j] = true;
                            first = first * 10 + arr[j];
                            k++;
                        }
                        j--;
                    }
                    ans = Math.min(ans, Math.abs(first-sec));
                }
                System.out.printf("%d\n", ans);
            }

        }
    }
}
